﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ModuleDALCore;
using DTO;

namespace DAL
{
	public class NHOMHANGDAO:DALBase
	{
		public NHOMHANGDAO()
        {
            this.OpenConnect();
        }
        private DataTable dt;
        private string _SpName;

        public string SpName
        {
            get { return "SPNHOMHANG"; }
            set { _SpName = value; }
        }
        public DataTable GetListNH()
        {
            dt = new DataTable();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new NHOMHANG(), null), ConvertClassToArray.GetValues(new NHOMHANG(), 0));
				return dt;
			}
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't list BC"); }
        }
		public List<NHOMHANG> GetListNHS()
		{
			dt = new DataTable();
			List<NHOMHANG> bc = new List<NHOMHANG>();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new NHOMHANG(), null), ConvertClassToArray.GetValues(new NHOMHANG(), 0));
				bc = (List<NHOMHANG>)ConvertDatatableToList.ConvertTo<NHOMHANG>(dt);
				return bc;
			}
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't list BC"); }
		}
        public String CreatenewId()
        {
            try
            {
                return "NH" + DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(new NHOMHANG(), null), ConvertClassToArray.GetValues(new NHOMHANG(), 1));

            }
			catch { return null;}// throw new InvalidExpressionException("Msg1: Can't Create new BC"); }
        }
        public bool INSERT(NHOMHANG cv)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 2)) == 1);

            }
			catch { return false; }// throw new InvalidExpressionException("Msg1: Can't Insert new BC"); }
        }
        public bool UPDATE(NHOMHANG cv)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 3)) == 1);

            }
			catch { return false;}// throw new InvalidExpressionException("Msg1: Can't Update  BC"); }
        }
        public bool DELETE(NHOMHANG cv)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 4)) ==1);

            }
			catch { return false;}// throw new InvalidExpressionException("Msg1: Can't Delete  BC"); }
        }
	}
}
